package co.flante.services;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * <p>Title: EntityManagerProvider</p>
 * <p>Description: This is really just a convenience so that I don't have to create a factory and set it up
 * every time I want to get an entity manager.</p>
 * @author Mike Haas, Aaron Cook, Kyle Kolstad
 * @email michael.haas.@my.uwrf.edu, aaron.cook@my.uwrf.edu, kyle.kolstad@my.uwrf.edu
 * @date 11/25/2013
 */
public class EntityManagerProvider {
    public EntityManagerProvider() {}

    /**
     * Perform the get operation for the entity manager.
     *
     * @return the entity manager for this api
     */
    public EntityManager get() {
        String persistenceUnitName = play.Play.application().configuration().getString("jpa.default");
        EntityManagerFactory emFactory = Persistence.createEntityManagerFactory(persistenceUnitName);

        return emFactory.createEntityManager();
    }
}